package com.efast.dmom.aps.datahandlers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.aps.bean.Equipment;
import com.efast.dmom.aps.bean.WorkCenter;
import com.efast.dmom.aps.bean.Workshop;
import com.efast.dmom.aps.dao.EquipmentDao;
import com.efast.dmom.aps.dao.WorkCenterDao;
import com.efast.dmom.aps.entity.WorkshopEntity;
import com.efast.dmom.aps.util.TimeUtil;

/**
 * @author Aaron Liu
 *
 * @date:2020年2月4日
 */
@Component
public class EquipmentDataHandler {

	@Autowired
	private EquipmentDao equipmentDao;
	
	@Autowired
	private WorkCenterDao workCenterDao;

	public void saveEquipmentList(List<Equipment> equipList) {

		if (equipList == null) {
			return;
		}

		equipmentDao.saveEquipmentList(equipList);
	}
	
	public void save(Equipment obj) {

		if (obj.getInnerData() != null) {
			obj.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
			obj.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setCreator(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//			obj.getInnerData().setCreationPid(DataHandlerUtils.getDmomPid());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
			obj.getInnerData().setRowStatus(1);
			obj.getInnerData().setRowTrxId(111);
			equipmentDao.save(obj.getInnerData());
		}
	}

	public void update(Equipment obj) {

		if (obj.getInnerData() != null) {

			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());

			equipmentDao.update(obj.getInnerData());
		}
	}

	public void delete(Equipment obj) {
		if (obj.getInnerData() != null) {

			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());

			equipmentDao.delete(obj.getInnerData());
		}
	}

	public Equipment getById(long id) {
		Equipment equipment = new Equipment();
		equipment.setInnerData(equipmentDao.getById(id));
		return equipment;
	}

	public Equipment getByName(String name) {
		Equipment equipment = new Equipment();
		equipment.setInnerData(equipmentDao.getByName(name));
		return equipment;
	}


	public Equipment getByCode(String equipmentpCode) {
		Equipment equipment = new Equipment();
		equipment.setInnerData(equipmentDao.getByCode(equipmentpCode));
		return equipment;
	}
	

}
